#ifndef _APPS_BBOXD_CMASTER_H_
#define _APPS_BBOXD_CMASTER_H_

#include <buola/buola.h>
#include <buola/io/csocketacceptor.h>
#include <map>

#include "cservice.h"

namespace buola { namespace bboxd {

class CClient;
class CRemote;
    
class CMaster
{
public:
    CMaster();
    ~CMaster();

    void RegisterClient(CClient *pClient);
    void UnregisterClient(CClient *pClient);

    CClient *GetClient(uint64_t pUID);
    
    bool RegisterService(const std::string &pAddress,CClient *pClient,uint64_t pUID);
    bool UnregisterService(const std::string &pAddress,CClient *pClient);

    //this just gets by address... more sophisticated search at a later point.
    CService* GetService(const std::string &pAddress);
    
//    void RegisterRemote(CRemote *pRemote);
//    void UnregisterRemote(CRemote *pRemote);

//    CRemote *RemoteByHost(const std::string &pHost);
//    CRemote *RemoteByUUID(const std::string &pUUID);
    
    const std::string &UUID()   {   return mUUID;   }

private:
    void OnNewLocalConnection(io::PSocket pSocket);
//    void OnNewRemoteConnection(io::PSocket pSocket);
//    void OnNewPeerConnection(io::PSocket pSocket);

    std::string mUUID;
    
    std::map<uint64_t,CClient*> mClients;
    std::map<std::string,CService> mServices;
    
    std::unique_ptr<io::CSocketAcceptor> mLocalAcceptor;

//    std::map<std::string,CRemote*> mRemotesByHost;
//    std::map<std::string,CRemote*> mRemotesByUUID;

//    std::map<uint64_t,io::PSocket> mPeerConnections;
};

/*namespace bboxd*/ } /*namespace buola*/ }

#endif
